/**
 * @Author 韦建韩
 * @Date 2022/3/24
 */
package com.zczn.order_system.controller;

import com.zczn.order_system.constant.HttpCodeConstant;
import com.zczn.order_system.entity.pojo.Result;
import com.zczn.order_system.exception.CustomException;
import com.zczn.order_system.exception.SystemException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionController {
    @ExceptionHandler({CustomException.class})
    @ResponseBody
    public Result defaultExceptionHandler(CustomException e){
        Result result = new Result();
        result.setCode(e.getCode());
        result.setData(e.getMessage());
        return result;
    }
//    @ExceptionHandler({Exception.class})
    @ResponseBody
    public Result SystemExceptionHandler(Exception e){
        Result result = Result.doCreate();
        result.setCode(HttpCodeConstant.Field.ServerError.code);
        result.setData("系统异常，请联系客服");
        return result;
    }
}
